package com.ltv.xiangqibook.web;

import java.util.Date;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Text;

/**
 * This class defines the methods for basic operations of create, update & retrieve
 * for the post entity
 * 
 * @author
 *
 */
public class Answer {

	/**
	 * Create the answer
	 * 
	 * @param id
	 *          : id of the answer
	 * @param post_id
	 *          : post id
	 * @param author
	 *          : author
	 * @param content
	 *          : content
	 * @param created_time
	 *          : created time
	 *
	 * @return persisted answer
	 */
	public static void createAnswer(Long id, String post_id, String author, Text content, Date created_time) {
		Entity answer = new Entity("answers", id);

		answer.setProperty("post_id", post_id);
		answer.setProperty("author", author);
		answer.setProperty("content", content);
		answer.setProperty("created_time", created_time);

		Util.persistEntity(answer);
	}

	/**
	 * Return all the answers by post_id
	 * 
	 * @return answers
	 */
	public static Iterable<Entity> getAllanswersByPostId(String post_id) {
		return Util.listEntities("answers", "post_id", post_id);
	}

}
